<!DOCTYPE html>
<!--
  ~ Copyright (c) 2018.
  ~ This file was written by fancyears·milos·malvis @connor. Any question/bug you can post to 1243093366@qq.com.
  ~ ALL RIGHTS RESERVED.
  -->
<html xmlns:th="http://www.thymeleaf.org">
<meta charset="UTF-8">
<title>关联工程师表</title>
</head>
<body>
<input id="url" type="hidden" value="vwo/queryByBase"/>
<div class="panel-body" style="padding-bottom:0px;">
    <form class="form-horizontal" id="cntForm" role="form" method="post">
        <fieldset>
            <div class="panel panel-default" style="margin-top: 10px;">
                <input th:value="${vwoId}" type="hidden" id="vwoId" name="vwoId"/>
                <input type="hidden" id="personId" name="personId"/>
                <div class="panel-body">
                    <div class="col-lg-6">
                        <label>请展开部门选择人员</label>
                        <ul id="orgGroupTree" class="ztree" style="width:400px; overflow:auto;"></ul>
                    </div>
                    <div class="col-lg-6">
                        <div class="form-group col-lg-12">
                            <label for="personName">关联工程师名:</label>
                            <input type="text" class="form-control" name="personName" id="personName"
                                   placeholder="请选择工程师"/>
                        </div>
                        <div class="form-group col-lg-12">
                            <label for="personDeptName">所属部门:</label>
                            <input type="text" class="form-control" name="personDeptName" id="personDeptName"
                                   disabled="disabled"
                            />
                        </div>
                        <div class="form-group col-lg-12">
                            <label for="partId">关联零件号:</label>
                            <input type="text" class="form-control" name="partId" id="partId"
                                   placeholder="请输入关联零件号"/>
                        </div>
                        <div class="form-group col-lg-12">
                            <label for="partName">关联零件名称:</label>
                            <input type="text" class="form-control" name="partName" id="partName"
                                   placeholder="请输入关联零件名称"/>
                        </div>
                    </div>
                </div>
            </div>
        </fieldset>
    </form>
</div>
<script th:src="@{/js/helper/projectHelper.js}"></script>
<script th:src="@{/js/helper/dateFormater.js}"></script>
<!--<script th:src="@{/js/helper/disableEnterKey.js}"></script>-->
<script th:inline="javascript">
    <![CDATA[
    var setting = {
        check: {
            enable: false
        },
        view: {
            // addHoverDom: addHoverDom,
            // removeHoverDom: removeHoverDom,
            dblClickExpand: false,
            showLine: true,
            selectedMulti: false
        },
        data: {
            simpleData: {
                enable: true,
                idKey: "uid",
                pIdKey: "pUid",
                rootPId: "0"
            }
        },
        callback: {
            beforeClick: function (treeId, treeNode) {
                var zTree = $.fn.zTree.getZTreeObj('orgGroupTree');
                if (treeNode.isParent) {
                    zTree.expandNode(treeNode);
                    return false;
                } else {
                    return true;
                }
            },
            onClick: function (event, treeId, treeNode) {
                console.log(treeId);
                $("#personName").val(treeNode.name);
                let userId = treeNode.uid;
                $.ajax({
                    type: "GET",
                    //ajax需要添加打包名
                    url: "./vwo/getUserDetail?uid=" + userId,
                    success: function (result) {
                        if (result.status) {
                            $("#personDeptName").val(result.groupName);
                            $("#personId").val(result.personId);
                        }
                    },
                    error: function (e) {
                        console.error("连接服务器异常:" + e.status);
                    }
                });
            }
        }
    };
    $(
        initZTree = function () {
            $.post("./vwo/getUserAndGroup", function (info) {
                var t = $("#orgGroupTree");
                t = $.fn.zTree.init(t, setting, info.data);
            })
        }
    );
    $(function () {
        $('#cntForm').bootstrapValidator({
            message: 'This value is not valid',
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                partId: {
                    message: '零件号未输入',
                    validators: {
                        notEmpty: {
                            message: ' 请输入正确的零件号'
                        }
                    }
                },
                // pColorCode: {
                //     message: '颜色代号验证失败',
                //     validators: {
                //         notEmpty: {
                //             message: '颜色代号不能为空'
                //         },
                //         threshold: 1, //有1字符以上才发送ajax请求，（input中输入一个字符，插件会向服务器发送一次，设置限制，6字符以上才开始）
                //         remote: {//ajax验证。server result:{"valid",true or false} 向服务发送当前input name值，获得一个json数据。例表示正确：{"valid",true}
                //             url: 'colorSet/validateCodeWithPuid',//验证地址
                //             message: '颜色代号已存在',//提示消息
                //             delay: 500,//每输入一个字符，就发ajax请求，服务器压力还是太大，设置2秒发送一次ajax（默认输入一个字符，提交一次，服务器压力太大）
                //             // *自定义提交数据，默认值提交当前input value
                //             data: function (validator) {
                //                 return {
                //                     puid: $('#puid').val(),
                //                     pColorCode: $("#pColorCode").val()
                //                 };
                //             },
                //             type: 'POST'//请求方式
                //         }
                //     }
                // }
            }
        });
        $("#btnOk", window.top.document).click(function () {
            var bootstrapValidator = $("#cntForm", window.top.document).data('bootstrapValidator');
            bootstrapValidator.validate();
            //重新验证字段
            // bootstrapValidator.revalidateField("pColorAbolishDate");
            // bootstrapValidator.revalidateField("pColorEffectedDate");
            if (bootstrapValidator.isValid()) {
                let data = {};
                var _d = $("#cntForm").serializeArray();
                for (var p in _d) {
                    data[_d[p].name] = _d[p].value;
                }
                console.log(data);
                JSON.stringify(data);
                $.ajax({
                    contentType:
                        "application/json",
                    type:
                        'POST',
                    data: JSON.stringify(data),
                    url: "./vwo/saveInformChanger",
                    success: function (result) {
                        $('.modal-dialog', window.top.document).parent('div').remove();
                        $('body', window.top.document).find('.modal-backdrop').remove();
                        $(window.parent.document).contents().find(".tab-pane.fade.active.in iframe")[0].contentWindow.doRefreshConnectedTable();
                        undead();
                        if (result.status) {
                            layer.msg(result.msg, {icon: 1, time: 2000});
                            // $(window.parent.document).contents().find(".tab-pane.fade.active.in iframe")[0].contentWindow.reloadSheet();//.find('#' + result.type).text(result.name);
                        }
                        else {
                            window.Ewin.alert({message: result.msg});
                        }
                    },
                    error: function (e) {
                        console.error("连接服务器异常:" + e.status);
                    }
                });
            }
        })

    })
    ]]>
</script>
</body>
</html>